public class Solution2 {
        public static boolean isAnagram(String s, String t) {
            int len1 = s.length();
            int len2 = t.length();
            if (len1 != len2) {
                return false;
            }
            int[] hash = new int[26];

            for (int i = 0; i < len1; i++) {
                hash[s.charAt(i)-'a']++;
            }
            for (int i = 0; i < len1; i++) {
                hash[t.charAt(i)-'a']--;
            }
            for (int  i = 0; i < 26; i++) {
                if (hash[i] != 0) {
                    return false;
                }
            }
            return true;
        }

        public static void main(String[] args) {
            String s = "nnaab";
            String t = "nnbaa";
            System.out.println(isAnagram(s,t));
        }

}

